package com.person.leetcode.editor.cn;

/**
 * 26.删除有序数组中的重复项
 * 2022-05-05 17:51:19
 **/
public class Sequence_0026_RemoveDuplicatesFromSortedArray {
    public static void main(String[] args) {
        Solution solution = new Sequence_0026_RemoveDuplicatesFromSortedArray().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int removeDuplicates(int[] nums) {
            //a,b a指向生成数组的最后一为,b指向候选位,如果 valb > vala,a 就是重复的,需要保证 vala < valb
            int a = 0, b = a + 1;
            int len = nums.length;
            if (len < 2) {
                return len;
            }
            while (b < len) {
                if (nums[a] != nums[b]){
                    nums[++a] = nums[b++];
                }else{
                    ++b;
                }
            }
            return a+1;

        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
